package sword.T5;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-03-23 1:08:39 星期三
 */

class Solution {
    public String replaceSpace(String s) {
        int n = s.length();
        for (int i=0; i<s.length(); ++i) {
            if (s.charAt(i) == ' ')
                n+=2;
        }
        char[] chs = new char[n];
        int j = n-1;
        for (int i=s.length()-1; i>=0; --i) {
            if (s.charAt(i) == ' ') {
                chs[j--] = '0';
                chs[j--] = '2';
                chs[j--] = '%';
            } else
                chs[j--] = s.charAt(i);
        }
        return String.valueOf(chs);
    }
}